package com.guigu.thirdpartyservices.controller;

import com.guigu.gulicommon.context.UserContext;
import com.guigu.gulicommon.entity.pojo.res.Res;
import com.guigu.gulicommon.entity.vo.UserInformationByGiteeVo;
import com.guigu.thirdpartyservices.service.ThirdPartLoginService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * 第三方登陆相关接口
 */
@Log4j2
@RestController
@RequestMapping("/login")
public class ThirdPartLoginController {

    @Autowired
    private ThirdPartLoginService thirdPartLoginService;

    /**
     * 通过Gitee获取用户信息
     * <p>
     * 通过Gitee三方登陆获取获取到的code解析用户信息
     *
     * @param code Gitee返回的code
     * @return UserInformationOByGiteeVo 用户信息
     */
    @GetMapping("/gitee/{code}")
    public Res<UserInformationByGiteeVo> parseLoginSingerByGitee(@PathVariable String code) throws IOException {
        log.info("线程变量为:{}", UserContext.getInstance().getCurrentUser());
        return thirdPartLoginService.parseLoginSigerByGitee(code);
    }
}
